package nconv.convert.generator;

import nconv.convert.ConvertContext;
import nconv.convert.ConvertContext.DOC_TYPE;
import nconv.convert.DocUtils;
import nconv.convert.TGPPRefProcessor;
import nconv.utils.LogCenter;
import nconv.wiki.MediaWikiProxy;

import java.util.List;

/**
 * Created by xiaobyu on 4/27/2016.
 */
public class TGPPPageRemoval {
    public static void main(String[] args) throws Exception {
        TGPPRefProcessor.reloadRefs(false);

        String[] specs = new String[]{"29212"}; //SPEC_NAME_ARRAY;

        MediaWikiProxy proxy = MediaWikiProxy.getWikiSite(MediaWikiProxy.WikiSite.AUTO_WIKI);
        ConvertContext.setDocType(DOC_TYPE.TGPP);
        for (String spec: specs) {
            ConvertContext.setDocName(DocUtils.getSpecDocFileName(spec));
            List<String> pages = TGPPRefProcessor.getSpecPages(spec);

            if (pages == null) {
                System.err.println("Failed to find any pages for spec: " + spec);
            }
            pages.add(spec);

            for (String page : pages) {
                if (proxy.hasPage(page)) {
                    proxy.deletePage(page, "Programmed cleanup");
                    LogCenter.logWiki(page, LogCenter.DOC_OPERATION.DELETE);
                }
            }
        }
        LogCenter.updateLogs();

    }
}
